//
//  LZQ_Utils.swift
//  SwiftExercise
//
//  Created by King on 2021/6/18.
//

import UIKit

class LZQ_Utils: NSObject {
    
    class func isBlankString(num:String?) -> String {
        if num == nil {
            return ""
        }
        return num!
    }
}

protocol Calculatable {
    
    //Mark:计算富文本的高度
    static func attributedTextHeight(text: NSAttributedString,width: CGFloat) -> CGFloat
    
    //Makk:计算文本的高度
    static func textHeight(text: String,fontSize: CGFloat,width: CGFloat) -> CGFloat
    
    //Mark:计算文本的宽度
    static func textWidth(text: String,fontSize: CGFloat,height: CGFloat) -> CGFloat
    
}

extension Calculatable{
    //Mark:计算富文本的高度
    static func attributedTextHeight(text: NSAttributedString,width: CGFloat) -> CGFloat{
        return text.boundingRect(with: CGSize(width: width, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, context: nil).size.height + 5.0
    }
    
    //Mark:计算文本的高度
    static func textHeight(text: String,fontSize: CGFloat,width: CGFloat) -> CGFloat{
        return text.boundingRect(with: CGSize(width: width, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: [.font: UIFont.systemFont(ofSize: fontSize)], context: nil).size.height + 5
    }
    
    /// 计算文本的宽度
    static func textHieght(text: String, fontSize: CGFloat, height: CGFloat) -> CGFloat {
        return text.boundingRect(with: CGSize(width: CGFloat(MAXFLOAT), height: height), options: .usesLineFragmentOrigin, attributes: [.font: UIFont.systemFont(ofSize: fontSize)], context: nil).size.height
    }
    
}
